package com.ruoyi.web.controller.course;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CoursePart;
import com.ruoyi.course.service.ICoursePartService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系Controller
 *
 * @author mac
 * @date 2023-03-11
 */
@RestController
@RequestMapping("/course/coursePart")
public class CoursePartController extends BaseController
{
    @Autowired
    private ICoursePartService coursePartService;

    /**
     * 查询系列表
     */
    @PreAuthorize("@ss.hasPermi('course:coursePart:list')")
    @GetMapping("/list")
    public TableDataInfo list(CoursePart coursePart)
    {
        startPage();
        List<CoursePart> list = coursePartService.selectCoursePartList(coursePart);
        return getDataTable(list);
    }

    /**
     * 导出系列表
     */
    @PreAuthorize("@ss.hasPermi('course:coursePart:export')")
    @Log(title = "系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CoursePart coursePart)
    {
        List<CoursePart> list = coursePartService.selectCoursePartList(coursePart);
        ExcelUtil<CoursePart> util = new ExcelUtil<CoursePart>(CoursePart.class);
        util.exportExcel(response, list, "系数据");
    }

    /**
     * 获取系详细信息
     */
    @PreAuthorize("@ss.hasPermi('course:coursePart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(coursePartService.selectCoursePartById(id));
    }

    /**
     * 新增系
     */
    @PreAuthorize("@ss.hasPermi('course:coursePart:add')")
    @Log(title = "系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CoursePart coursePart)
    {
        return toAjax(coursePartService.insertCoursePart(coursePart));
    }

    /**
     * 修改系
     */
    @PreAuthorize("@ss.hasPermi('course:coursePart:edit')")
    @Log(title = "系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CoursePart coursePart)
    {
        return toAjax(coursePartService.updateCoursePart(coursePart));
    }

    /**
     * 删除系
     */
    @PreAuthorize("@ss.hasPermi('course:coursePart:remove')")
    @Log(title = "系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(coursePartService.deleteCoursePartByIds(ids));
    }
}
